package enums;

import java.util.ArrayList;
import java.util.List;

public enum ActivityCityEnum {
    BeiJing(11, "北京"),
    ShangHai(21, "上海"),
    NanJing(31, "南京"),
    HeFei(41, "合肥"),
    WuHan(51, "武汉"),
    XiAn(61, "西安");
    private int id;
    private String name;

    ActivityCityEnum(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //根据id查询类型
    public static ActivityCityEnum getById(int id) {
        for (ActivityCityEnum city : ActivityCityEnum.values()) {
            if (city.id == id) {
                return city;
            }
        }
        return null;
    }
    //返回所有类型
    public static List<ActivityCityEnum> getAllCity() {
        List<ActivityCityEnum> cityEnumList = new ArrayList<>();
        //遍历，将元素添加至集合中
        for (ActivityCityEnum city : ActivityCityEnum.values()) {
            cityEnumList.add(city);
        }
        return cityEnumList;
    }
}
